package com.usermanage.Filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 過客 on 2018/3/9
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        //注入过滤器
        registration.setFilter(new WebFilter());
        //拦截规则
        registration.addUrlPatterns("*.page");
        registration.addUrlPatterns("*.json");
//        registration.addUrlPatterns("/*");
        //初始化赋值
//        registration.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/reg");
        //过滤器名称
        registration.setName("WebFilter");
        //是否自动注册 false 取消Filter的自动注册
        registration.setEnabled(true);
        //过滤器顺序
        registration.setOrder(1);
//        registration.setDispatcherTypes(DispatcherType.REQUEST);
        return registration;
    }
}
